package com.ljy.generator;

import com.ljy.model.MainTemplateConfig;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * 模板生成，静态+动态
 */
public class MainTemplate {
    public static void main(String[] args) throws TemplateException, IOException {
        //静态文件生成
        //获取用户根目录
        String userHome = System.getProperty("user.dir");
        //模板文件路径
        String templatePath = userHome + File.separator + "code-generator-demo" + File.separator + "acm-template";
        //生成文件路径
        String outPath = userHome;
        //调用复制方法
        StaticGenerator.generate(templatePath, outPath);

        //动态文件生成
        String projectPath = System.getProperty("user.dir");
        String inputPath = projectPath + File.separator + "code-generator-basic" + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "templates" + File.separator + "MainTemplate.java.ftl";
        String outputPath = projectPath + File.separator + "acm-template/src/com/ljy/acm/MainTemplate.java";
        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
        mainTemplateConfig.setAuthor("lll");
        mainTemplateConfig.setLoop(true);
        mainTemplateConfig.setOutputText("计算结果：");
        DynamicGenerator.doGenerate(inputPath, outputPath, mainTemplateConfig);
    }
}
